#!/usr/bin/env python3
"""
应用配置管理
"""

from pydantic import Field
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """应用配置"""

    # 应用配置
    APP_NAME: str = "新易访内网系统"
    DEBUG: bool = Field(default=False, description="调试模式")
    HOST: str = Field(default="127.0.0.1", description="监听地址")
    PORT: int = Field(default=8000, description="监听端口")

    # 数据库配置
    DATABASE_URL: str = Field(default="sqlite+aiosqlite:///./evintro.db", description="数据库连接字符串")

    # 加密配置
    AES_ENCRYPTION_KEY: str = Field(
        default="2V6X9a8zPqR7tYw3s5v8y/B?E(H+MbQeThWmZq4t6w9z$",
        description="AES-256加密密钥，必须为32字节base64编码",
        min_length=44,
        max_length=44
    )
    JWT_SECRET_KEY: str = Field(
        default="J@NcRfUjXn2r5u8x/A?D(G+KaPdSgVkYp3s6v9y$B&E)H@McQeThWmZq4t7w!",
        description="JWT签名密钥，至少32字符",
        min_length=32
    )
    ACCESS_TOKEN_EXPIRE_MINUTES: int = Field(default=30, description="访问令牌有效期（分钟）", ge=1)

    # CORS配置
    CORS_ORIGINS: list[str] = Field(default=["http://localhost:3000", "http://127.0.0.1:3000"], description="允许的跨域源")

    # 二维码配置
    QRCODE_EXPIRE_MINUTES: int = Field(default=30, description="二维码有效期（分钟）", ge=1)

    # 审计配置
    AUDIT_LOG_RETENTION_DAYS: int = Field(default=90, description="审计日志保留天数", ge=1)

    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"
        case_sensitive = False


# 全局配置实例
settings = Settings()
